!(function (doc, win) {
    var docEle = doc.documentElement,//获取html元素
        event = "onorientationchange" in window ? "orientationchange" : "resize",//判断是屏幕旋转还是resize;
        fn = function () {
            var width = docEle.clientWidth;
            width && (docEle.style.fontSize = 100 * (width / 750) + "px");//设置html的fontSize，随着event的改变而改变。
        };

    win.addEventListener(event, fn, false);
    doc.addEventListener("DOMContentLoaded", fn, false);

}(document, window));

$(function(){
	
//=======================预约===========================
	$(".tea-list li").on("click",".order-btn",function(){
		layer.open({
			type:0,
			title: ["预约","padding: 10px 30px;height: 30px;line-height: 30px;background: #f7f7f7;border-bottom: 1px solid #cccccc;"],
			content:'<div class="order-box">'+
						'<form action="#">'+
							'<input type="hidden" value=""/>'+
							'<p><span>姓名：</span><input type="text" placeholder="请输入姓名" data-require="*" data-tip="请输入姓名"/></p>'+
							'<p><span>手机号：</span><input type="text" placeholder="请输入手机号" data-require="phone" data-tip="请输入手机号"/></p>'+
							'<input type="submit" value="提交" onclick="return check()"/>'+
						'</form>'+
					'</div>',
			className:"order-pop"
		})
	})
	$("#tea-box").on("click",".order-btn",function(){
		layer.open({
			type:10,
			title: ["预约","padding: 10px 30px;height: 30px;line-height: 30px;background: #f7f7f7;border-bottom: 1px solid #cccccc;"],
			content:'<div class="order-box">'+
						'<form action="#">'+
							'<input type="hidden" value=""/>'+
							'<p><span>姓名：</span><input type="text" placeholder="请输入姓名" data-require="*" data-tip="请输入姓名"/></p>'+
							'<p><span>手机号：</span><input type="text" placeholder="请输入手机号" data-require="phone" data-tip="请输入手机号"/></p>'+
							'<input type="submit" value="提交" onclick="return check()"/>'+
						'</form>'+
					'</div>',
			className:"order-pop"
		})
	})
	function yuyue(id){
		layer.open({
			type:10,
			title: ["预约","padding: 10px 30px;height: 30px;line-height: 30px;background: #f7f7f7;border-bottom: 1px solid #cccccc;"],
			content:'<div class="order-box">'+
			'<form action="#">'+
			'<input type="hidden" value="'+id+'" id="teachid"/>'+
			'<p><span>姓名：</span><input type="text" placeholder="请输入姓名" data-require="*" data-tip="请输入姓名"/></p>'+
			'<p><span>手机号：</span><input type="text" placeholder="请输入手机号" data-require="phone" data-tip="请输入手机号"/></p>'+
			'<input type="submit" value="提交" onclick="return check()"/>'+
			'</form>'+
			'</div>',
			className:"order-pop"
		})
	}
//=================预约   end==========================
//================登录==================
	$(".login-btn").click(function(){
		layer.open({
			type:9,
			title: ["登录","padding: 10px 30px;height: 30px;line-height: 30px;background: #f7f7f7;border-bottom: 1px solid #cccccc;"],
			content:'<div class="order-box">'+
						'<form action="#">'+
							'<p><span>用户名：</span><input type="text" placeholder="请输入用户名" data-require="*" data-tip="请输入用户名"/></p>'+
							'<p><span>密码：</span><input type="password" placeholder="请输入密码" data-require="*" data-tip="请输入密码"/></p>'+
							'<input type="submit" value="提交" onclick="return check()"/>'+
						'</form>'+
					'</div>',
			className:"order-pop"
		})
	})
//===========登录  end====================

})
//表单验证
function check(){
	var phonereg= /^1[34578]\d{9}$/;
	var agereg= /^(?:[1-9][0-9]?|1[01][0-9]|120)$/;
	var flag=true;
	$("*[data-require]").each(function(){
		var require=$(this).attr("data-require");
		var finput=$.trim($(this).val())
		var tip=$(this).attr("data-tip");
		switch(require){
			case "*":
					if(''==finput){
						 var tippop=layer.open({
						 	type:3,
						    content: tip
						    ,skin: 'msg'
						    ,time: 2 //2秒后自动关闭
						  });
						flag=false;
						return false;
					}
					break;
			case "phone":
					if(!phonereg.test(finput)){
						 layer.open({
						 	type:3,
						    content: tip
						    ,skin: 'msg'
						    ,time: 2 //2秒后自动关闭
						  });
						flag=false;
						return false;
					}
					break;
			case "age":
					if(!agereg.test(finput)){
						 layer.open({
						 	type:3,
						    content: tip
						    ,skin: 'msg'
						    ,time: 2 //2秒后自动关闭
						  });
						flag=false;
						return false;
					}
					break;
			case "pwd":
				if(''==finput){
					layer.open({
						type:3,
					    content: tip
					    ,skin: 'msg'
					    ,time: 2 //2秒后自动关闭
					  });
					flag=false;
					return false;
				}
				break;
			case "surepwd":
					if(finput!=$.trim($("input[data-require='pwd']").val())){
						layer.open({
							type:3,
						    content: tip
						    ,skin: 'msg'
						    ,time: 2 //2秒后自动关闭
						  });
						flag=false;
						return false;
					}
					break;
			case "username":
				if(''==finput){
					var tippop=layer.open({
						type:3,
						content: tip
						,skin: 'msg'
						,time: 2 //2秒后自动关闭
					});
					flag=false;
					return false;
				}else{
					$.ajax({
						url:url+'checkusername',
						dataType:'json',
						type:'post',
						async:false,
						data:{'username':finput},
						success:function(result){
							// console.log(result);
							var status = result.status;
							var code = result.code;
							if(status==1&&code=='1005'){
								layer.open({
									type:3,
									content: '该用户名已经存在'
									,skin: 'msg'
									,time: 2 //2秒后自动关闭
								});
								flag=false;
								return false;
							}
						},
						error:function(result) {
							console.log("error")
						}

					});
				}

				break;
		}
		
	});
	
	return flag;
}

//表单验证  end